package main

import (
	"encoding/json"
	"fmt"
	"reflect"
)

type Person struct {
	Name string
	Age int
	IsMan bool
	Money int
}

type Student struct{
	Person

	List []string
	mp map[string]string

}

func main() {

	m := make(map[string]interface{}, 5)
	m["Name"] = "hell"
	m["Age"] = 10
	m["IsMan"] = true
	m["List"] = []string{"h33", "43w"}
	m["mp"] = map[string]string{"ddd":"eeeeee"}
	m["sss"] = true
	fmt.Printf("m :%+v \n", m)
	res, _ := json.Marshal(m)
	fmt.Println("Marshal res", string(res))

	//JSON反序列化：JSON格式的字符串-->结构体
	student := Student{}
	err := json.Unmarshal(res, &student)
	if err != nil {
		fmt.Println("err ", err)
	}
	fmt.Printf("Unmarshal res: %+v \n", student)



	str := `{"Name":"stu00", "Money":34444444, "IsMan":true, "Age":30, "List":["dd","cc"]}`
	c1 := &Student{}
	err = json.Unmarshal([]byte(str), c1)
	if err != nil {
		fmt.Println("json unmarshal failed!")
		return
	}
	fmt.Printf("%#v\n", c1)


	test1()

}

func test1(){
	str := `{
		"id": "order_FW90O3zzV2UyT3",
		"entity": "order",
		"amount": 1000000,
		"amount_paid": 1000000,
		"amount_due": 0,
		"currency": "INR",
		"receipt": "Receipt no. 1",
		"offer_id": null,
		"status": "paid",
		"attempts": 2,
		"notes": {
			"notes_key_1": "Tea, Earl Grey, Hot",
			"notes_key_2": "Tea, Earl Grey… decaf."
		},
		"created_at": 1598609298
	}`

	body := map[string]interface{}{}
	json.Unmarshal([]byte(str), &body)

	fmt.Println(body)
	notes := body["notes"].(map[string]interface{})
	fmt.Println(notes["notes_key_1"].(string))

	if body["status"] == "paid" {
		//订单未完成
		fmt.Println(" paid ", reflect.TypeOf(body["status"]))
	}
}